package com.simon.customer.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.simon.customer.entity.DishType;
import com.simon.customer.entity.Dishes;
import com.simon.customer.service.IService;
import com.simon.customer.service.impl.Service;

public class DishesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private IService service = new Service();

	public DishesServlet() {
		super();

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String mId = request.getParameter("m_id");
		
		
		String mName = service.showMerchantName(mId);
		String dishTypeId = request.getParameter("t_id");
		
		Map<String, Dishes> dish = new HashMap<>();
		List<DishType> list = service.showDishTypeByMId(mId);
		
		Map<String, DishType> type = new HashMap<>();
		for (DishType dt : list) {
			type.put(dt.getTypeId(), dt);
		}
		request.setAttribute("type", type);
		//某个商家下拉菜品列表
		
		if (dishTypeId != null) {
			request.setAttribute("tId", dishTypeId);// 品种id
			List<Dishes> typetemp = service.searchDishesByType(mId, dishTypeId);
			for (Dishes d : typetemp) {
				dish.put(d.getFoodName(), d);
			}
			request.setAttribute("dishes", dish);
		} else {
			List<Dishes> dishes = service.searchDishes(mId);
			for (Dishes d : dishes) {
					dish.put(d.getFoodName(), d);
				}
				request.setAttribute("dishes", dish);

		}
		// 菜列表
		request.setAttribute("mName", mName);// 商家名字标题
		request.setAttribute("mId", mId);
		if (dish != null) {
			request.getRequestDispatcher("dishes.jsp").forward(request,
					response);
		}
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

}
